<template>
  <div>
    <table>
      <tr>
        <td>用户名hh</td>
        <td><input type="text" v-model="loginData.name" /></td>
      </tr>
      <tr>
        <td>密码</td>
        <td><input type="password" v-model="loginData.pwd" /></td>
      </tr>
      <tr>
        <td>注册时间</td>
        <td><input type="date" v-model="loginData.date" /></td>
      </tr>
      <tr>
        <td colspan="2"><input type="button" value="注册" @click="login" /></td>
      </tr>
    </table>
  </div>
</template>

<script setup lang="ts">
import { reactive, toRefs } from 'vue';
import { useRouter } from 'vue-router';
var router = useRouter();
import axios from 'axios';

let data = reactive({
  loginData: {
    name: '',
    pwd: '',
    date: ''
  }
});

let { loginData } = toRefs(data);

const login = () => {
  if(loginData.value.name==''){
    alert("用户名不能为空");
    return;
  }
  axios({
    url:'http://localhost:61961/api/Login/LoginInfo',
    method:'post',
    data:{
      Lname:loginData.value.name,
      Lpwd:loginData.value.pwd,
      Ldate:loginData.value.date
    }
  }).then(res=>{
    console.log(res)
    if(res.data==-1){
      alert("用户名已经存在");
      return;
    }else{
      alert("注册成功");
      router.push('/register');
    }
  }).catch(err=>{
    console.log(err)
  })

  console.log(loginData.value);
  
};
</script>

<style scoped></style>
